package com.tisson.action;

import java.util.ArrayList;
import java.util.List;

import com.tisson.bo.PurviewBO;
import com.tisson.bo.SDMUBO;
import com.tisson.comment.WebConstants;
import com.tisson.pojo.Page;

public class SDMUAction extends ActionSup{
	
	private String userId;
	private String doorId;
	private String departmentId;
	private List deparmentList;
	private List userList;
	private List result;
	private Page page;
	
	public String userList(){
		page = new Page();
		List all;
		result = new ArrayList();
		SDMUBO bo = new SDMUBO();
		deparmentList = bo.getOptionDep(request);
		userList = bo.getOptionUser(departmentId);
		try{
			all = bo.getUserVOList(doorId, request);
		}catch(Exception e){
			e.printStackTrace();
			all = new ArrayList();
		}
		request.getSession().setAttribute("list", all);
		if(!all.isEmpty()){
			for(int i=0;i<WebConstants.PAGESIZE&&i<all.size();i++){
				result.add(all.get(i));
			}
		}
		page.setCurrentPage(1);
		page.setPrePage(page.getCurrentPage()-1);
		page.setNextPage(page.getCurrentPage()+1);
		page.setListSize(all.size());
		page.setTotalPages(page.getListSize()%WebConstants.PAGESIZE==0?page.getListSize()/WebConstants.PAGESIZE:(page.getListSize()/WebConstants.PAGESIZE)+1);
		return "userList";
	}
	
	public String activity(){
		PurviewBO bo =  new PurviewBO();
		bo.changeStateActivity(userId, doorId);
		return userList();
	}
	
	public String inactivity(){
		PurviewBO bo =  new PurviewBO();
		bo.changeStateInactivity(userId, doorId);
		return userList();
	}
	
	public String delete(){
		PurviewBO bo =  new PurviewBO();
		bo.delete(userId, doorId);
		return userList();
	}
	
	public String add(){
		PurviewBO bo =  new PurviewBO();
		bo.add(userId, doorId);
		return userList();
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getDoorId() {
		return doorId;
	}

	public void setDoorId(String doorId) {
		this.doorId = doorId;
	}

	public String getDepartmentId() {
		return departmentId;
	}

	public void setDepartmentId(String departmentId) {
		this.departmentId = departmentId;
	}

	public List getDeparmentList() {
		return deparmentList;
	}

	public void setDeparmentList(List deparmentList) {
		this.deparmentList = deparmentList;
	}

	public List getUserList() {
		return userList;
	}

	public void setUserList(List userList) {
		this.userList = userList;
	}

	public List getResult() {
		return result;
	}

	public void setResult(List result) {
		this.result = result;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

}
